clear
set more off
set matsize 4000
cd "/Users/alee87/Dropbox/Job Reservation/Replication"




clear
use "36151-0001-Data copy.dta"


merge m:1 IDHH using "36151-0002-Data copy.dta"
drop MB* SM* MG* FM* OG* QC* FU* WA* MP6* CD*  OH* MI* DB* CO*  AN* FM* AP* AD* _merge

merge m:1  ID12ANM STATEID using "ihds_caste.dta"
drop _merge
replace newcaste=ID12ANM if newcaste==""
replace newcaste="BHUDDIST" if newcaste=="BHUDDIST "



merge m:1  newcaste STATEID using "caste_level.dta"
drop _merge sc st obc

merge m:1  newcaste STATEID using "castelist copy.dta"
drop _merge sname
recode inlist (.=0)

merge m:1 STATEID using "states_notes.dta"
drop _merge

drop if obc_res_year==.



*****Make the Independent variables
rename RO5 age 
rename RO3 male
recode male (2=0)

gen married=RO6
recode married (0=1)
replace married=0 if married>1

recode HS3Y (.=2012)
gen birthyear =2012-age


gen year18=birthyear+17

gen obc=0
replace obc=1 if ID13==3


replace obc=0 if lateaddition>=year18 &obc==1&lateaddition!=.

gen oldstate=state
replace oldstate="Bihar" if state=="Jharkhand"
replace oldstate="Uttar Pradesh" if state=="Uttarakhand"
replace oldstate="Madhya Pradesh" if state=="Chhattisgarh"

egen test1=mean(obc), by(oldstate)
egen test2=mean(obc), by(state)

gen stateobc=test1*100
replace stateobc=test2*100 if year>2000
drop test* state_caste_count

gen state_res_year=0
replace state_res_year=1 if year18>=obc_res_year

drop if year18>HS3Y
drop if year18<1964

keep if ID13<4
*DDD
gen period=0
replace period =1 if year18>1993

gen stategrp=0
replace stategrp =1 if obc_res_year>1990

gen castgrp=0
replace castgrp=1 if obc==1


         gen nationaltreat=0
		 replace nationaltreat=1 if period==1 &castgr ==1
		 
** DDD FE



gen caste4=0
replace caste4=1 if ID13==4 
replace caste4=2 if ID13==5
replace caste4=3 if obc==1

gen mandalcasteyear=0
replace mandalcasteyear=1 if period==1 &stategrp==1&castgrp==1
replace mandalcasteyear=. if year18==1991 &obc_res_year==1991&castgrp==1
replace mandalcasteyear=. if year18==1992 &obc_res_year==1991&castgrp==1
replace mandalcasteyear=. if year18==1993 &obc_res_year==1991&castgrp==1

gen yearmandal=0
replace yearmandal=1 if period==1 &stategrp==1
replace yearmandal=. if year18==1991 &obc_res_year==1991
replace yearmandal=. if year18==1992 &obc_res_year==1991
replace yearmandal=. if year18==1993 &obc_res_year==1991


gen statecaste=STATEID*10+ caste4
gen casteyear=year18*10+ caste4
gen stateyear=STATEID*100+(year18-1947)
gen stateperiod=STATEID*10+(period)



*FE
gen reserved=0
replace reserved=1 if obc==1 &state_res_year==1

gen unaffected=0
replace unaffected=1 if state=="Kerala"
replace unaffected=1 if state=="Karnataka"
replace unaffected=1 if state=="Gujarat"
replace unaffected=1 if state=="Tamil Nadu"
replace unaffected=1 if state=="Andhra Pradesh"



*ages
do "alternateage copy.do"

***movement
*individual movement
gen one=1
egen state_caste_count=total(one), by(newcaste STATEID)

gen yscaste_obc=0
replace yscaste_obc=1 if ID13==3
egen scaste_obc=total(yscaste_obc), by(newcaste STATEID)
gen yscaste_sc=0
replace yscaste_sc=1 if ID13==4
egen scaste_sc=total(yscaste_sc), by(newcaste STATEID)
gen yscaste_st=0
replace yscaste_st=1 if ID13==5
egen scaste_st=total(yscaste_st), by(newcaste STATEID)
drop ys*

gen jati_prop_obc=scaste_obc/state_caste_count
gen jati_prop_sc=scaste_sc/state_caste_count
gen jati_prop_st=scaste_st/state_caste_count
gen jati_prop_gen=1-jati_prop_st-jati_prop_sc-jati_prop_obc

gen jaticaste=.
replace jaticaste=1 if jati_prop_gen>.9
replace jaticaste=2 if jati_prop_st>.9
replace jaticaste=3 if jati_prop_sc>.9
replace jaticaste=4 if jati_prop_obc>.9

gen statejcaste=STATEID*10+ inlist
gen jcasteyear=year18*10+ inlist

gen caste1j=0
replace caste1j=1 if jaticaste==4
replace caste1j=. if jaticaste==.

gen anomalouscat=0
replace anomalouscat=1 if jati_prop_gen>.5 &caste4!=0
replace anomalouscat=1 if jati_prop_st>.5 &caste4!=2
replace anomalouscat=1 if jati_prop_sc>.5 &caste4!=1
replace anomalouscat=1 if jati_prop_obc>.5 &caste4!=3
replace anomalouscat=1 if state_caste_count<3

gen jmandalcasteyear=0
replace jmandalcasteyear=1 if period==1 &stategrp==1&jaticaste==4
replace jmandalcasteyear=. if year18==1991 &obc_res_year==1991&jaticaste==4
replace jmandalcasteyear=. if year18==1992 &obc_res_year==1991&jaticaste==4
replace jmandalcasteyear=. if year18==1993 &obc_res_year==1991&jaticaste==4
replace jmandalcasteyear=. if jaticaste==.


*subquota
gen mbc=0
replace mbc=1 if obcsubquota!=""
egen statembc=mean(mbc), by (oldstate)

gen caste5=caste4
replace caste5=5 if obcsubquota!=""

gen statecaste5=STATEID*10+ caste5
gen caste5year=year18*10+ caste5


gen zperiod=0
replace zperiod =1 if year18>1988

gen zstategrp=.
replace zstategrp =1 if state=="Tamil Nadu"
replace zstategrp =0 if state=="Kerala"
replace zstategrp =0 if state=="Andhra Pradesh"
replace zstategrp =0 if state=="Gujarat"
replace zstategrp =0 if state=="Maharashtra"


gen zcastgrp=0
replace zcastgrp=1 if obcsubquota!=""




****the dependent variables

*education and ses

rename ED2 literate

rename ED6 yearsofeducation

gen english=0
replace english=1 if ED3>1
replace english=. if ED3==.

gen attendedcollege =0
replace attend=1 if yearsof>12
replace attend=. if yearsof==.
replace attend=. if age<21

gen graduatedcollege =0
replace graduatedcollege=1 if yearsof>14
replace graduatedcollege=. if yearsof==.
replace graduatedcollege=. if age<23

gen income=INCOME
*replace income=1 if income<1
gen loghhincome=log(income) 
replace loghhincome =. if  RO4!=1

gen professionalocc=0
replace professionalocc=1 if WS4<51
replace professionalocc=. if WS4==.
replace professionalocc=. if age<25

gen govjob=0
replace govjob=1 if  WS14==1
replace govjob=. if  WS14>3
replace govjob=. if  WS14==.
replace govjob=. if age<23|age>60

gen formalsect=0
replace formalsect=1 if  RO7>6&RO7<10
replace  formalsect=. if age<23|age>60
replace  formalsect=. if RO7>10

recode WS10AN WS12 WS11MEALSRS  WS11HOUSERS WSEARNNONAG WSEARNAG WSEARNNREGA(.=0)
gen logwages=log( WSEARNNONAG+WSEARNAG)

rename ASSETS assets
replace assets=. if  RO4!=1


drop CG1A CG9 CG10 CGM CG11 CG24 CG25 CG4
factor CG*
predict factor1
replace factor1=. if  RO4!=1

sum professionalocc loghhincome  graduatedcollege attendedcollege english  yearsofeducation literate  factor1

**contacts 
egen numberofcontacts=rsum(SN2*)
replace numberofcontacts=numberofcontacts-SN2G1-SN2G2-SN2H1-SN2H2-SN2K1-SN2K2
gen contactbinary=0
replace contactbinary=1 if numberofcontacts>0

egen numberofseniorcontacts=rsum(SN2A1 SN2A2 SN2C1 SN2C2 SN2E1 SN2E2 SN2I1 SN2I2 )
gen seniorcontactbinary=0
replace seniorcontactbinary=1 if numberofseniorcontacts>0

egen numberofcontacts_caste=rsum(SN2*1)
replace numberofcontacts_caste=numberofcontacts-SN2G1-SN2H1-SN2K1
gen contactbinary_caste=0
replace contactbinary_caste=1 if numberofcontacts_caste>0

egen numberofseniorcontacts_caste=rsum(SN2A1  SN2C1  SN2E1  SN2I1 )
gen seniorcontactbinary_caste=0
replace seniorcontactbinary_caste=1 if numberofseniorcontacts_caste>0
replace seniorcontactbinary_caste=. if EDUC7>12


sum seniorcontactbinary contactbinary seniorcontactbinary_caste contactbinary_caste





***conditioning effects 

gen test=.
replace test= yearsofeducation  if RO4==1&male==1
egen edyearshead=mean(test) ,by(IDHH)
drop test

gen edyearsfather=.
replace edyearsfather=ID18C if RO4<3
replace edyearsfather=edyearshead if RO4>2 &RO4<5

gen edfath=0
egen statefather=mean(edyearsfather), by(STATEID)
replace edfath=1 if edyearsfather>0
replace edfath=. if edyearsfather==.

gen hedfath=0
replace hedfath=1 if edyearsfather>12
replace hedfath=. if edyearsfather==.

egen castemeaneducation=mean(years) , by(newcaste state period)
replace castemeaneducation=. if period==1
egen catmeaneducation=mean(years) , by(caste4 state period)
replace catmeaneducation=. if period==1

egen caste_mean_education=mean(castemeaneducation) , by(newcaste state)
egen cat_mean_education=mean(catmeaneducation) , by(newcaste state)
drop castemeaneducation catmeaneducation


gen educatedcaste =0
replace educatedcaste =1 if caste_mean_education>cat_mean_education
rename educatedcaste edcaste
replace edcaste=0 if castgrp==0

sum edcaste  edfath

gen edstatecaste=0
replace edstatecaste=statecaste if edfath==1
gen edstateyear=0
replace edstateyear=stateyear if edfath==1
gen edcasteyear=0
replace edcasteyear=casteyear if edfath==1

gen x_edstateyear=0
replace x_edstateyear=x_stateyear if edfath==1
gen x_edcasteyear=0
replace x_edcasteyear=x_casteyear if edfath==1



gen x_int_north_obc_post_edfath=x_int_north_obc_post*edfath

gen q_int_north_obc_post_edfath=q_int_north_obc_post*edfath

gen u_int_north_obc_post_edfath=u_int_north_obc_post*edfath

gen v_int_north_obc_post_edfath=v_int_north_obc_post*edfath

gen hedstatecaste=0
replace hedstatecaste=statecaste if hedfath==1
gen hedstateyear=0
replace hedstateyear=stateyear if hedfath==1
gen hedcasteyear=0
replace hedcasteyear=casteyear if hedfath==1

gen x_hedstateyear=0
replace x_hedstateyear=x_stateyear if hedfath==1
gen x_hedcasteyear=0
replace x_hedcasteyear=x_casteyear if hedfath==1



gen x_int_north_obc_post_hedfath=x_int_north_obc_post*hedfath

gen q_int_north_obc_post_hedfath=q_int_north_obc_post*hedfath

gen u_int_north_obc_post_hedfath=u_int_north_obc_post*hedfath

gen v_int_north_obc_post_hedfath=v_int_north_obc_post*hedfath

gen hedstatejcaste=0
replace hedstatejcaste=statejcaste if hedfath==1

gen hedjcasteyear=0
replace hedjcasteyear=jcasteyear if hedfath==1
sum edcaste  edfath

gen edstatejcaste=0
replace edstatejcaste=statejcaste if edfath==1

gen edjcasteyear=0
replace edjcasteyear=jcasteyear if edfath==1

***attitudes
rename ME8 casteassociation
replace casteassociation =. if ID11!=1

rename TR1 casteconflict
recode casteconf (2=1) (3=0)

gen untouchabityexperience=TR4A
*replace untouchabityexperience =. if caste4==2
*replace untouchabityexperience =. if caste4==1
replace untouchabityexperience =. if ID11!=1

rename MP2A intercastemarriage

rename RC3D castecertificate

gen lineartrend=year18-1979 
label var  lineartrend "Time Trend"
gen obc_lineartrend=year18-1979 
replace obc_lineartrend=0 if ID13!=3
label var  obc_lineartrend "OBC*Time Trend"

sum  castecertificate  intercastemarriage untouchabityexperience  casteconflict casteassociation

**interactions
gen int_obc=castgr 
gen int_post94=period
gen int_northstate=stategr
gen int_obc_north=castgr *stategr
gen int_obc_post94=castgr*period
gen int_north_post94=stategr*period
gen int_north_obc_post=castgr *stategr*period

gen jint_obc=inlist
gen jint_post94=period
gen jint_northstate=stategr
gen jint_obc_north=inlist *stategr
gen jint_obc_post94=inlist*period
gen jint_north_post94=stategr*period
gen jint_north_obc_post=inlist *stategr*period

gen int_obc_post_edfath=int_obc_post94*edfath
gen int_north_obc_post_edfath=int_north_obc_post*edfath

gen jint_obc_post_edfath=jint_obc_post94*edfath
gen jint_north_obc_post_edfath=jint_north_obc_post*edfath
gen jint_obc_post_hedfath=jint_obc_post94*hedfath
gen jint_north_obc_post_hed=jint_north_obc_post*hedfath

gen x_int_obc_post_hedfath=x_int_obc_post94*hedfath
gen x_int_obc_post_edfath=x_int_obc_post94*edfath

gen xj_int_obc_post_hedfath=inlist*hedfath*x_int_post94
gen xj_int_obc_post_edfath=inlist*edfath*x_int_post94
gen xj_int_obc_post94=inlist*x_int_post94


gen int_obc_post_hedfath=int_obc_post94*hedfath
gen int_north_obc_post_hedfath=int_north_obc_post*hedfath




label var  int_obc "OBC Caste"
label var  int_post94  "Post 1994"
label var  int_northstate  "Mandal State"
label var  int_obc_north  "OBC Caste*Mandal State"
label var  int_obc_post94  "OBC*Post 94"
label var  int_north_post94  "Post 94*Mandal State"
label var  int_north_obc_post "OBC*Post 94*Mandal State"



label var  x_int_obc "OBC Caste"
label var  x_int_post94  "Post 1994"
label var  x_int_northstate  "Mandal State"
label var  x_int_obc_north  "OBC Caste*Mandal State"
label var  x_int_obc_post94  "OBC*Post 94"
label var  x_int_north_post94  "Post 94*Mandal State"
label var  x_int_north_obc_post "OBC*Post 94*Mandal State"


label var  q_int_obc "OBC Caste"
label var  q_int_post94  "Post 1994"
label var  q_int_northstate  "Mandal State"
label var  q_int_obc_north  "OBC Caste*Mandal State"
label var  q_int_obc_post94  "OBC*Post 94"
label var  q_int_north_post94  "Post 94*Mandal State"
label var  q_int_north_obc_post "OBC*Post 94*Mandal State"

label var  v_int_obc "OBC Caste"
label var  v_int_post94  "Post 1994"
label var  v_int_northstate  "Mandal State"
label var  v_int_obc_north  "OBC Caste*Mandal State"
label var  v_int_obc_post94  "OBC*Post 94"
label var  v_int_north_post94  "Post 94*Mandal State"
label var  v_int_north_obc_post "OBC*Post 94*Mandal State"


label var  u_int_obc "OBC Caste"
label var  u_int_post94  "Post 1994"
label var  u_int_northstate  "Mandal State"
label var  u_int_obc_north  "OBC Caste*Mandal State"
label var  u_int_obc_post94  "OBC*Post 94"
label var  u_int_north_post94  "Post 94*Mandal State"
label var  u_int_north_obc_post "OBC*Post 94*Mandal State"



label var  jint_obc "OBC Caste"
label var  jint_post94  "Post 1994"
label var  jint_northstate  "Mandal State"
label var  jint_obc_north  "OBC Caste*Mandal State"
label var  jint_obc_post94  "OBC*Post 94"
label var  jint_north_post94  "Post 94*Mandal State"
label var  jint_north_obc_post "OBC*Post 94*Mandal State"

*****TABLE B1****
sutex yearsofeducation govjob seniorcontactbinary_caste hedfath  age married int_obc int_post94 int_northstate  if year18>1979, label 


*/
***models

*****TABLE 1, TABLE 3****
set more off
*SES
           foreach var of varlist govjob  yearsofeducation   seniorcontactbinary_caste   {

		   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
		   reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend  [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_`var',  ctitle(17) keep(temp_int_obc temp_int_post94 temp_int_obc_post94 lineartrend obc_lineartrend  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' temp_int_obc_post94   lineartrend obc_lineartrend i.statecaste i.stateyear [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_`var',  ctitle(17) keep(temp_int_obc_post94  lineartrend obc_lineartrend )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append  label nocon
drop temp*

 gen  temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   	      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend  [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_`var',  ctitle(13) keep(temp_int_obc temp_int_post94 temp_int_obc_post94 lineartrend obc_lineartrend  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

reg `var' temp_int_obc_post94   lineartrend obc_lineartrend   i.statecaste i.x_stateyear [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_`var',  ctitle(13) keep(temp_int_obc_post94  lineartrend obc_lineartrend )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}


     *****TABLES C1, C2, C3****
 set more off
           foreach var of varlist    yearsofeducation govjob  seniorcontactbinary_caste   {
  		   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		   gen temp_int_northstate =int_northstate 
		   gen temp_int_obc_north  = int_obc_north
		   gen temp_int_north_post94 = int_north_post94 
		   gen temp_int_north_obc_post= int_north_obc_post
		   
		   		   copydesc int_obc  temp_int_obc
		   copydesc int_post94  temp_int_post94
		   copydesc int_obc_post94  temp_int_obc_post94
		   copydesc int_northstate   temp_int_northstate 
		   copydesc int_obc_north    temp_int_obc_north
		   copydesc int_north_post94   temp_int_north_post94 
		   copydesc int_north_obc_post  temp_int_north_obc_post
		   
  reg `var'  temp_int_obc temp_int_post94 temp_int_northstate temp_int_obc_post94 temp_int_obc_north temp_int_north_post94 temp_int_north_obc_post [pweight=WT]  if year18>1979, vce(cluster IDHH)
 outreg2 using ddd_`var',  ctitle(17)  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon
 reg  `var'    temp_int_north_obc_post   i.statecaste i.stateyear i.casteyear   [pweight=WT]  if year18>1979, vce(cluster IDHH)
 outreg2 using ddd_`var',  ctitle(17) keep( temp_int_north_obc_post  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, YES) append tex(frag) label nocon
drop temp*
 
    gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   gen temp_int_northstate =x_int_northstate 
		   gen temp_int_obc_north  = x_int_obc_north
		   gen temp_int_north_post94 = x_int_north_post94 
		   gen temp_int_north_obc_post= x_int_north_obc_post
		   
		   		   		   copydesc int_obc  temp_int_obc
		   copydesc int_post94  temp_int_post94
		   copydesc int_obc_post94  temp_int_obc_post94
		   copydesc int_northstate   temp_int_northstate 
		   copydesc int_obc_north    temp_int_obc_north
		   copydesc int_north_post94   temp_int_north_post94 
		   copydesc int_north_obc_post  temp_int_north_obc_post
		   
 reg `var'  temp_int_obc temp_int_post94 temp_int_northstate temp_int_obc_post94 temp_int_obc_north temp_int_north_post94 temp_int_north_obc_post [pweight=WT]  if year18>1979, vce(cluster IDHH)
 outreg2 using ddd_`var',  ctitle(13)  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon
 reg  `var'    temp_int_north_obc_post   i.statecaste i.x_stateyear i.x_casteyear   [pweight=WT]  if year18>1979, vce(cluster IDHH)
 outreg2 using ddd_`var',  ctitle(13) keep( temp_int_north_obc_post  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, YES) append tex(frag) label nocon
 drop temp*
 }
 
 
 **differential effects

*****TABLES 2 AND C4****

*12 year cutoff

rename x_int_post94 x_int_p94
set more off 
           foreach var of varlist  yearsofeducation  govjob   {
 reg `var' period##hedfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_12_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_hedfath   i.statecaste i.stateyear i.hedstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_12_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

 reg `var' x_period##hedfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_12_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_hedfath   i.statecaste i.x_stateyear i.hedstatecaste i.x_hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_12_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

}
rename  x_int_p94 x_int_post94

*5 year cutoff
            foreach var of varlist  yearsofeducation  govjob   {
			gen temp=0
			drop temp*
			gen temp_period=period
 reg `var' temp_period##edfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_0_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_edfath   i.statecaste i.stateyear i.edstatecaste i.edstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_0_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_edfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

replace temp_period=x_period
 reg `var' temp_period##edfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_0_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_edfath   i.statecaste i.x_stateyear i.edstatecaste i.x_edstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_0_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_edfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}


****LEADS AND LAGS*****
 *****TABLES E2,E4 AND E6****
**25
             foreach var of varlist  yearsofeducation  govjob  seniorcontactbinary_caste{
reg `var' u_int_obc u_int_post94 u_int_obc_post94   [pweight=WT]  if year26>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using u_`var',  ctitle(`var') keep(u_int_obc u_int_post94 u_int_obc_post94  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' u_int_obc_post94     i.statecaste i.u_stateyear [pweight=WT]  if year26>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using u_`var',  ctitle(`var') keep(u_int_obc_post94  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append label nocon
 reg `var'  u_int_obc u_int_post94 u_int_northstate u_int_obc_post94 u_int_obc_north u_int_north_post94 u_int_north_obc_post [pweight=WT]  if year26>1979, vce(cluster IDHH)
 outreg2 using u_`var',  ctitle(`var')  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon
 reg  `var'    u_int_north_obc_post   i.statecaste i.u_stateyear i.u_casteyear   [pweight=WT]  if year26>1979, vce(cluster IDHH)
 outreg2 using u_`var',  ctitle(`var') keep( u_int_north_obc_post  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, YES) append tex(frag) label nocon

 }

 *****TABLES E1,E3 AND E5****
**21
             foreach var of varlist  yearsofeducation assets   govjob  seniorcontactbinary_caste{
reg `var' v_int_obc v_int_post94 v_int_obc_post94   [pweight=WT]  if year22>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using v_`var',  ctitle(`var') keep(v_int_obc v_int_post94 v_int_obc_post94  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' v_int_obc_post94     i.statecaste i.v_stateyear [pweight=WT]  if year22>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using v_`var',  ctitle(`var') keep(v_int_obc_post94  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append label nocon
 reg `var'  v_int_obc v_int_post94 v_int_northstate v_int_obc_post94 v_int_obc_north v_int_north_post94 v_int_north_obc_post [pweight=WT]  if year22>1979, vce(cluster IDHH)
 outreg2 using v_`var',  ctitle(`var')  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon
 reg  `var'    v_int_north_obc_post   i.statecaste i.v_stateyear i.v_casteyear   [pweight=WT]  if year22>1979, vce(cluster IDHH)
 outreg2 using v_`var',  ctitle(`var') keep( v_int_north_obc_post  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, YES) append tex(frag) label nocon

 }

 
 *****TABLES D1-D3****
 **10
             foreach var of varlist  yearsofeducation     govjob seniorcontactbinary_caste {
reg `var' q_int_obc q_int_post94 q_int_obc_post94   [pweight=WT]  if year10>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using q_`var',  ctitle(`var') keep(q_int_obc q_int_post94 q_int_obc_post94  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' q_int_obc_post94     i.statecaste i.q_stateyear [pweight=WT]  if year10>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using q_`var',  ctitle(`var') keep(q_int_obc_post94  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append label nocon
 reg `var'  q_int_obc q_int_post94 q_int_northstate q_int_obc_post94 q_int_obc_north q_int_north_post94 q_int_north_obc_post [pweight=WT]  if year10>1979, vce(cluster IDHH)
 outreg2 using q_`var',  ctitle(`var')  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon
 reg  `var'    q_int_north_obc_post   i.statecaste i.q_stateyear i.q_casteyear   [pweight=WT]  if year10>1979, vce(cluster IDHH)
 outreg2 using q_`var',  ctitle(`var') keep( q_int_north_obc_post  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, YES) append tex(frag) label nocon
 }
 
 
 *********controls
  *****TABLES F1-F3****
gen temp=.
drop temp*
set more off
           foreach var of varlist   yearsofeducation govjob  seniorcontactbinary_caste    {

		   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
		   reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94   male  i.ID11   edyearsfather [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_control_`var',  ctitle(17) keep(temp_int_obc temp_int_post94 temp_int_obc_post94  )  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' temp_int_obc_post94     i.statecaste i.stateyear male  i.ID11  edyearsfather  [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using dd_control_`var',  ctitle(17) keep(temp_int_obc_post94  )  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append  label nocon
drop temp*

  gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   	      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94   male  i.ID11  edyearsfather [pweight=WT]  if year14>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using dd_control_`var',  ctitle(13) keep(temp_int_obc temp_int_post94 temp_int_obc_post94  )  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

reg `var' temp_int_obc_post94     i.statecaste i.x_stateyear male  i.ID11   edyearsfather [pweight=WT]  if year14>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using dd_control_`var',  ctitle(13) keep(temp_int_obc_post94  )  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}



  *****TABLES F4-F5****
  *controls differential effects

set more off 

 

		   
           foreach var of varlist  yearsofeducation  govjob   {
		   gen temp=.
drop temp*
   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		   gen temp_int_northstate =int_northstate 
		   gen temp_int_obc_north  = int_obc_north
		   gen temp_int_north_post94 = int_north_post94 
		   gen temp_int_north_obc_post= int_north_obc_post
		   gen temp_int_obc_post_hedfath=int_obc_post_hedfath
		   
		   		   copydesc int_obc  temp_int_obc
		   copydesc int_post94  temp_int_post94
		   copydesc int_obc_post94  temp_int_obc_post94
		   copydesc int_northstate   temp_int_northstate 
		   copydesc int_obc_north    temp_int_obc_north
		   copydesc int_north_post94   temp_int_north_post94 
		   copydesc int_north_obc_post  temp_int_north_obc_post
		      copydesc  int_obc_post_hedfath temp_int_obc_post_hedfath
			  
 reg `var' temp_int_post94##hedfath##temp_int_obc   male  i.ID11   edyearsfather [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_controls_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' temp_int_obc_post94 temp_int_obc_post_hedfath   male  i.ID11   edyearsfather i.statecaste i.stateyear i.hedstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_controls_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

drop temp*
    gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   gen temp_int_northstate =x_int_northstate 
		   gen temp_int_obc_north  = x_int_obc_north
		   gen temp_int_north_post94 = x_int_north_post94 
		   gen temp_int_north_obc_post= x_int_north_obc_post
		   	   gen temp_int_obc_post_hedfath=x_int_obc_post_hedfath
		   
		   		   		   copydesc int_obc  temp_int_obc
		   copydesc int_post94  temp_int_post94
		   copydesc int_obc_post94  temp_int_obc_post94
		   copydesc int_northstate   temp_int_northstate 
		   copydesc int_obc_north    temp_int_obc_north
		   copydesc int_north_post94   temp_int_north_post94 
		   copydesc int_north_obc_post  temp_int_north_obc_post
		        copydesc  int_obc_post_hedfath x_int_obc_post_hedfath
		   
 reg `var' temp_int_post94##hedfath##temp_int_obc   male  i.ID11   edyearsfather  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_controls_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' temp_int_obc_post94 temp_int_obc_post_hedfath  i.statecaste i.x_stateyear i.hedstatecaste i.x_hedstateyear   male  i.ID11   edyearsfather [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_controls_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

}


           foreach var of varlist  yearsofeducation  govjob   {
		   gen temp=.
		   drop temp*
		      gen temp_int_post94=int_post94
		     gen temp_int_obc=int_obc
		   gen temp_int_obc_post94=int_obc_post94
		   	   gen temp_int_obc_post_edfath=int_obc_post_edfath
			   
 reg `var' temp_int_post94##edfath##temp_int_obc   male  i.ID11   edyearsfather [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_controls0_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' temp_int_obc_post94 temp_int_obc_post_edfath   male  i.ID11   edyearsfather i.statecaste i.stateyear i.edstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_controls0_dd_`var',  ctitle(17) keep( temp_int_obc_post94 temp_int_obc_post_edfath     )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

drop temp*
    gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   gen temp_int_northstate =x_int_northstate 
		   gen temp_int_obc_north  = x_int_obc_north
		   gen temp_int_north_post94 = x_int_north_post94 
		   gen temp_int_north_obc_post= x_int_north_obc_post
		   	   gen temp_int_obc_post_edfath=x_int_obc_post_edfath
		   
		   		   		   copydesc int_obc  temp_int_obc
		   copydesc int_post94  temp_int_post94
		   copydesc int_obc_post94  temp_int_obc_post94
		   copydesc int_northstate   temp_int_northstate 
		   copydesc int_obc_north    temp_int_obc_north
		   copydesc int_north_post94   temp_int_north_post94 
		   copydesc int_north_obc_post  temp_int_north_obc_post
		        copydesc  int_obc_post_edfath x_int_obc_post_edfath
		   
 reg `var' temp_int_post94##edfath##temp_int_obc   male  i.ID11   edyearsfather  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_controls0_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' temp_int_obc_post94 temp_int_obc_post_edfath  i.statecaste i.x_stateyear i.edstatecaste i.x_edstateyear   male  i.ID11   edyearsfather [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_controls0_dd_`var',  ctitle(13) keep( temp_int_obc_post94 temp_int_obc_post_edfath  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

}
 




**individual movement
    *****TABLES G1, G2, G5****
drop temp*
           foreach var of varlist govjob  yearsofeducation   seniorcontactbinary_caste   {

		   gen temp_int_obc=jint_obc
		   gen temp_int_post94=jint_post94
		   gen temp_int_obc_post94=jint_obc_post94
		      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
		   reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend  [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using jati_`var',  ctitle(17) keep(temp_int_obc temp_int_post94 temp_int_obc_post94 lineartrend obc_lineartrend  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' temp_int_obc_post94   lineartrend obc_lineartrend i.statejcaste i.stateyear [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using jati_`var',  ctitle(17) keep(temp_int_obc_post94  lineartrend obc_lineartrend )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append  label nocon
drop temp*

 gen  temp_int_obc=jint_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_post94*temp_int_obc
		   label var temp_int_obc_post94 "Post 94*OBC"
		   	      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend  [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using jati_`var',  ctitle(13) keep(temp_int_obc temp_int_post94 temp_int_obc_post94 lineartrend obc_lineartrend  )  addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

reg `var' temp_int_obc_post94   lineartrend obc_lineartrend   i.statejcaste i.x_stateyear [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using jati_`var',  ctitle(13) keep(temp_int_obc_post94  lineartrend obc_lineartrend )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}

    *****TABLES G3, G4****
           foreach var of varlist  yearsofeducation  govjob   {
 reg `var' period##hedfath##inlist   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_jati_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' jint_obc_post94 jint_obc_post_hedfath   i.statejcaste i.stateyear i.hedstatejcaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_jati_dd_`var',  ctitle(17) keep(  jint_obc_post94 jint_obc_post_hedfath   )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

 reg `var' x_period##hedfath##inlist   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_jati_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' xj_int_obc_post94 xj_int_obc_post_hedfath   i.statejcaste i.x_stateyear i.hedstatejcaste i.x_hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_jati_dd_`var',  ctitle(13) keep( xj_int_obc_post94 xj_int_obc_post_hedfath     )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

}

 
            foreach var of varlist  yearsofeducation  govjob   {
			gen temp=0
			drop temp*
			gen temp_period=period
 reg `var' temp_period##edfath##inlist   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_0j_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' jint_obc_post94 jint_obc_post_edfath    i.statecaste i.stateyear i.edstatecaste i.edstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_0j_dd_`var',  ctitle(17) keep( jint_obc_post94 jint_obc_post_edfath   )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

replace temp_period=x_period
 reg `var' temp_period##edfath##inlist   [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using file2_0j_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' xj_int_obc_post94 xj_int_obc_post_edfath     i.statecaste i.x_stateyear i.edstatecaste i.x_hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using file2_0j_dd_`var',  ctitle(13) keep(xj_int_obc_post94 xj_int_obc_post_edfath   )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}
 
    *****TABLES H1, H4, H5****
*creamy layer
gen creamy =0
replace creamy=0

gen test=.
replace test= WS4 if RO4==1&male==1
egen headjob=mean(test) ,by(IDHH)
drop test

gen fatherjob =.
replace  fatherjob =ID18A if RO4<3
replace  fatherjob = headjob if RO4>2 &RO4<5

replace creamy=1 if fatherjob<30
replace creamy=0 if fatherjob==15|fatherjob==8|fatherjob==6|fatherjob==16|fatherjob==1|fatherjob==9
replace creamy=0 if edyearsfather<10
replace creamy=0 if int_obc==0


set more off

           foreach var of varlist  yearsofeducation govjob seniorcontactbinary_caste  {

set more off
   gen temp=.
drop temp*

		   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
		   reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94   lineartrend obc_lineartrend    [pweight=WT]  if year18>1979 &int_northstate==1&cream==0 , vce(cluster IDHH)
outreg2 using cream_`var',  ctitle(17) keep(temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend )  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' temp_int_obc_post94     i.statecaste i.stateyear  lineartrend obc_lineartrend   [pweight=WT]  if year18>1979 &int_northstate==1&cream==0  , vce(cluster IDHH)
outreg2 using cream_`var',  ctitle(17) keep(temp_int_obc_post94  lineartrend obc_lineartrend )  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append  label nocon
drop temp*

  gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		   	      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94   lineartrend obc_lineartrend    [pweight=WT]  if year14>1979&int_northstate==1&cream==0 , vce(cluster IDHH)
outreg2 using cream_`var',  ctitle(13) keep(temp_int_obc temp_int_post94 temp_int_obc_post94  lineartrend obc_lineartrend )  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

reg `var' temp_int_obc_post94     i.statecaste i.x_stateyear   lineartrend obc_lineartrend [pweight=WT]  if year14>1979&int_northstate==1&cream==0 , vce(cluster IDHH)
outreg2 using cream_`var',  ctitle(13) keep(temp_int_obc_post94   lineartrend obc_lineartrend)  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}




     *****TABLES H2, H3****

            foreach var of varlist  yearsofeducation  govjob   {
			gen temp_period=period
 reg `var' temp_period##hedfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1&cream==0 , vce(cluster IDHH)
outreg2 using cream2_12_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_hedfath   i.statecaste i.stateyear i.hedstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1&cream==0, vce(cluster IDHH)
outreg2 using cream2_12_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

replace temp_period=x_period
 reg `var' temp_period##hedfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 &cream==0, vce(cluster IDHH)
outreg2 using cream2_12_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_hedfath   i.statecaste i.x_stateyear i.hedstatecaste i.x_hedstateyear [pweight=WT] if year18>1979&int_northstate==1&cream==0, vce(cluster IDHH)
outreg2 using cream2_12_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_hedfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}


            foreach var of varlist  yearsofeducation  govjob   {
			gen temp=.
			drop temp*
			gen temp_period=period
 reg `var' temp_period##edfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1&cream==0 , vce(cluster IDHH)
outreg2 using cream2_0_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_edfath   i.statecaste i.stateyear i.edstatecaste i.edstateyear [pweight=WT] if year18>1979&int_northstate==1&cream==0, vce(cluster IDHH)
outreg2 using cream2_0_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_edfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon

replace temp_period=x_period
 reg `var' temp_period##edfath##castgr   [pweight=WT]  if year18>1979&int_northstate==1 &cream==0, vce(cluster IDHH)
outreg2 using cream2_0_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_edfath   i.statecaste i.x_stateyear i.edstatecaste i.x_edstateyear [pweight=WT] if year18>1979&int_northstate==1&cream==0, vce(cluster IDHH)
outreg2 using cream2_0_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_edfath    )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}
 
 *state year controls

gen obc_rule=0
replace obc_rule=1 if state=="Bihar" &year18>1990
replace obc_rule=1 if state=="Bihar" &year18==1979
replace obc_rule=1 if state=="Jharkhand" &year18==1979
replace obc_rule=1 if state=="Jharkhand" &year18>1990&year18<2001
replace obc_rule=1 if state=="Uttar Pradesh" &year18>1988&year18<1995
replace obc_rule=1 if state=="Uttar Pradesh" &year18>1997&year18<2000
replace obc_rule=1 if state=="Uttar Pradesh" &year18>2003&year18<2008
replace obc_rule=1 if state=="Uttarakhand" &year18>1988&year18<1995
replace obc_rule=1 if state=="Uttarakhand" &year18>1997&year18<2000
replace obc_rule=1 if state=="Madhya Pradesh" &year18>2004
replace obc_rule=1 if state=="Gujarat" &year18>2001
replace obc_rule=1 if state=="Haryana"
replace obc_rule=1 if state=="Rajasthan" &year18>1998&year18<2004
replace obc_rule=1 if state=="Rajasthan" &year18>2008
replace obc_rule=1 if state=="Karnataka" &year18>1990
replace obc_rule=1 if state=="Kerala" &year18>2006
replace obc_rule=1 if state=="Tamil Nadu"
replace obc_rule=0 if state=="Tamil Nadu" &year18>1991&year18<1996
replace obc_rule=0 if state=="Tamil Nadu" &year18>2001&year18<2006
gen obc_rule_obc=obc_rule*int_obc


gen x_obc_rule=0
replace x_obc_rule=1 if state=="Bihar" &year14>1990
replace x_obc_rule=1 if state=="Bihar" &year14==1979
replace x_obc_rule=1 if state=="Jharkhand" &year14==1979
replace x_obc_rule=1 if state=="Jharkhand" &year14>1990&year14<2001
replace x_obc_rule=1 if state=="Uttar Pradesh" &year14>1988&year14<1995
replace x_obc_rule=1 if state=="Uttar Pradesh" &year14>1997&year14<2000
replace x_obc_rule=1 if state=="Uttar Pradesh" &year14>2003&year14<2008
replace x_obc_rule=1 if state=="Uttarakhand" &year14>1988&year14<1995
replace x_obc_rule=1 if state=="Uttarakhand" &year14>1997&year14<2000
replace x_obc_rule=1 if state=="Madhya Pradesh" &year14>2004
replace x_obc_rule=1 if state=="Gujarat" &year14>2001
replace x_obc_rule=1 if state=="Haryana"
replace x_obc_rule=1 if state=="Rajasthan" &year14>1998&year14<2004
replace x_obc_rule=1 if state=="Rajasthan" &year14>2008
replace x_obc_rule=1 if state=="Karnataka" &year14>1990
replace x_obc_rule=1 if state=="Kerala" &year14>2006
replace x_obc_rule=1 if state=="Tamil Nadu"
replace x_obc_rule=0 if state=="Tamil Nadu" &year14>1991&year14<1996
replace x_obc_rule=0 if state=="Tamil Nadu" &year14>2001&year14<2006
gen x_obc_rule_obc=x_obc_rule*int_obc

gen migrant=0
replace migrant=1 if  NMIG5>0& NMIG5<20
gen obcmigrant=migrant*obc

label var  x_obc_rule_obc   "OBC CM*OBC"
label var  x_obc_rule  "OBC CM"
label var  obc_rule_obc     "OBC CM*OBC"
label var obc_rule  "OBC CM"
label var  obcmigrant     "Migrant*OBC"
label var  migrant     "Migrant"




     *****TABLES I1, I4, I5****
set more off

           foreach var of varlist  yearsofeducation govjob seniorcontactbinary_caste  {

set more off
   gen temp=.
drop temp*

		   gen temp_int_obc=int_obc
		   gen temp_int_post94=int_post94
		   gen temp_int_obc_post94=int_obc_post94
		      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
				
					gen temp_obc_rule=obc_rule
			gen temp_obc_rule_obc=obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
		   
		   reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94   temp_obc_rule_obc obcmigrant    migrant   lineartrend obc_lineartrend  [pweight=WT]  if year18>1979 &int_northstate==1 , vce(cluster IDHH)
outreg2 using gov_`var',  ctitle(17) keep(temp_int_obc temp_int_post94 temp_int_obc_post94   temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend)  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

reg `var' temp_int_obc_post94     i.statecaste i.stateyear  temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend  [pweight=WT]  if year18>1979 &int_northstate==1  , vce(cluster IDHH)
outreg2 using gov_`var',  ctitle(17) keep(temp_int_obc_post94   temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend)  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append  label nocon
drop temp*

  gen temp_int_obc=x_int_obc
		   gen temp_int_post94=x_int_post94
		   gen temp_int_obc_post94=x_int_obc_post94
		
	gen temp_obc_rule=x_obc_rule
			gen temp_obc_rule_obc=x_obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
				
		   	      copydesc int_obc  temp_int_obc
		    copydesc int_obc_post94 temp_int_obc_post94
			    copydesc int_post94 temp_int_post94
		   
reg `var' temp_int_obc temp_int_post94 temp_int_obc_post94    temp_obc_rule_obc obcmigrant    migrant   lineartrend obc_lineartrend  [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov_`var',  ctitle(13) keep(temp_int_obc temp_int_post94 temp_int_obc_post94  temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend )  addtext(Controls, YES,  State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

reg `var' temp_int_obc_post94     i.statecaste i.x_stateyear  temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend [pweight=WT]  if year14>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov_`var',  ctitle(13) keep(temp_int_obc_post94   temp_obc_rule_obc obcmigrant    migrant  lineartrend obc_lineartrend)  addtext(Controls, YES,  State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}




      *****TABLES I2, I3****

            foreach var of varlist  yearsofeducation  govjob   {
			gen temp_period=period
			gen temp_obc_rule=obc_rule
			gen temp_obc_rule_obc=obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
				
 reg `var' temp_period##hedfath##castgr temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov2_12_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_hedfath  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  i.statecaste i.stateyear i.hedstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using gov2_12_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_hedfath   temp_obc_rule_obc obcmigrant    migrant   )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon


drop temp*
	gen temp_obc_rule=x_obc_rule
			gen temp_obc_rule_obc=x_obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
				
gen temp_period=x_period
 reg `var' temp_period##hedfath##castgr  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov2_12_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_hedfath  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  i.statecaste i.x_stateyear i.hedstatecaste i.x_hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using gov2_12_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_hedfath    temp_obc_rule_obc obcmigrant    migrant  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}


          foreach var of varlist  yearsofeducation  govjob   {
		  gen temp=.
		  drop temp*
			gen temp_period=period
			gen temp_obc_rule=obc_rule
			gen temp_obc_rule_obc=obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
				
 reg `var' temp_period##edfath##castgr temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov2_0_dd_`var',  ctitle(17)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) replace label nocon

 reg `var' int_obc_post94 int_obc_post_edfath  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  i.statecaste i.stateyear i.hedstatecaste i.hedstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using gov2_0_dd_`var',  ctitle(17) keep( int_obc_post94 int_obc_post_edfath   temp_obc_rule_obc obcmigrant    migrant   )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon


drop temp*
	gen temp_obc_rule=x_obc_rule
			gen temp_obc_rule_obc=x_obc_rule_obc
			copydesc temp_obc_rule_obc obc_rule_obc
				copydesc temp_obc_rule obc_rule
				
gen temp_period=x_period
 reg `var' temp_period##edfath##castgr  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  [pweight=WT]  if year18>1979&int_northstate==1 , vce(cluster IDHH)
outreg2 using gov2_0_dd_`var',  ctitle(13)   addtext( State-Caste Category FE, NO, State-Birth Year FE, NO, Caste Category-Birth Year FE, NO) append label nocon

 reg `var' x_int_obc_post94 x_int_obc_post_edfath  temp_obc_rule  temp_obc_rule_obc obcmigrant    migrant  i.statecaste i.x_stateyear i.edstatecaste i.x_edstateyear [pweight=WT] if year18>1979&int_northstate==1, vce(cluster IDHH)
outreg2 using gov2_0_dd_`var',  ctitle(13) keep( x_int_obc_post94 x_int_obc_post_edfath    temp_obc_rule_obc obcmigrant    migrant  )  addtext( State-Caste Category FE, YES, State-Birth Year FE, YES, Caste Category-Birth Year FE, NO) append tex(frag) label nocon
drop temp*
}





